<?php
    // array for JSON response
    $response = array();
    // include db connect class
    require_once __DIR__ . '/db_connect.php';
    // connecting to db
    $db = new DB_CONNECT();
    // get all comments from comment table
    $result = mysql_query('SELECT COUNT(comment_id) AS total_comment, place.place_id, place.place_name, place.url_image, place.description
							FROM comment, place WHERE comment.place_id=place.place_id AND year(comment.time_comment) = year(NOW()) 
							AND month(comment.time_comment) = month(NOW()) GROUP BY place_id ORDER BY total_comment DESC LIMIT 5') or die(mysql_error());
    if (mysql_num_rows($result) > 0) {
            $response["comment"] = array();
            while ($row = mysql_fetch_array($result)) {
                    $comment = array(); 
					$comment['total_comment'] = $row['total_comment'];
                    $comment['place_id'] = $row['place_id'];
					$comment['place_name'] = $row['place_name'];
					$comment['url_image'] = $row['url_image'];
					$comment['description'] = $row['description'];
                    // push single product into final response array
                    array_push($response['comment'],$comment);
            }
            // success
        $response["success"] = 1;
            echo json_encode($response);
    }
    else{
        $response["comment"] = "No comment";
        $response["success"] = 0;
            echo json_encode($response);
    }
?>